home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-05 / drivers1.zip / ETHIIE.ASM < prev    next >
Assembly Source File  |  1992-01-20  |  9KB  |  359 lines

  1. version    equ    0
  2. ;History:245,1
  3.  
  4. ;  The following people have contributed to this code: David Horne, Eric
  5. ;  Henderson, and Bob Clements.
  6. ;
  7. ;  This packet driver for Nokia Data Ethernet IIe adapter is based
  8. ;  on the NE2000 driver.  Adaptation was made by Markku Toijala and
  9. ;  Markku Viima, Nokia Data Systems Oy, Helsinki, Finland.
  10.  
  11. ;  Copyright, 1988-1992, Russell Nelson, Crynwr Software
  12.  
  13. ;   This program is free software; you can redistribute it and/or modify
  14. ;   it under the terms of the GNU General Public License as published by
  15. ;   the Free Software Foundation, version 1.
  16. ;
  17. ;   This program is distributed in the hope that it will be useful,
  18. ;   but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. ;   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  20. ;   GNU General Public License for more details.
  21. ;
  22. ;   You should have received a copy of the GNU General Public License
  23. ;   along with this program; if not, write to the Free Software
  24. ;   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  25. ;
  26.  
  27.     include    defs.asm
  28.  
  29. code    segment    word public
  30.     assume    cs:code, ds:code
  31.  
  32. ;*****************************************************************************
  33. ;
  34. ;    Nokia Data Ethernet IIe controller board offsets
  35. ;    IO port definition (BASE in io_addr)
  36. ;*****************************************************************************
  37.  
  38. ND_DATAPORT    EQU    400h        ; ETHIIE Port Window.
  39. ND_INTF_REG    EQU    402h        ; ETHIIE Status Setup Register
  40. EN_OFF        equ    0h
  41.  
  42. ND_SOFT_RESET    equ    20h        ; bitmask for RESET bit
  43. ND_INTF_BNC    equ    00h        ; BNC (or TP) interface used
  44. ND_INTF_DIX    equ    40h        ; DIX interface used
  45. ND_INTF_ROM    equ    80h        ; ROM disable.
  46.  
  47.  
  48.     include    8390.inc
  49.  
  50. ;*****************************************************************************
  51. ;
  52. ;    Nokia Data EtherNet IIe controller RAM (16 kbytes) is 
  53. ;    organized into Transmit and Receive areas as:
  54. ;*****************************************************************************
  55.  
  56. SM_TSTART_PG    equ    00h    ; First page of TX buffer
  57. SM_RSTART_PG    equ    06h    ; Starting page of RX ring
  58. SM_RSTOP_PG    equ    40h    ; Last page +1 of RX ring
  59.  
  60. ram_enable    macro
  61.     endm
  62.  
  63. reset_8390    macro
  64.     loadport
  65.     setport    ND_INTF_REG
  66.     in    al,dx            ; read current value
  67.     or    al,ND_SOFT_RESET     ; set RESET bit in reg.
  68.     out    dx,al            ; And write register
  69.     longpause
  70.     xor    al,ND_SOFT_RESET     ; Reset RESET bit in reg.
  71.     out    dx,al            ; Write back
  72.     longpause
  73.  
  74. ;-----
  75. ; Set IRQ Selection according to Interrupt Number.
  76. ;-----
  77.         loadport
  78.         setport ND_INTF_REG
  79.         mov    al,int_no
  80.         mov    ah,01h                ; Suppose IRQ5.
  81.         cmp    al,05                ; But is really?
  82.         je    int_ok                ; Yes, skip over.
  83.         mov    ah,02                ; Suppose IRQ2/9.
  84.         cmp    al,09                ; But is really?
  85.         je    int_ok                ; Yes, skip over.
  86.         mov    ah,04                ; Suppose IRQ12.
  87.         cmp    al,12                ; But is really?
  88.         je    int_ok                ; Yes, skip over. 
  89.         mov    ah,08h                ; Suppose IRQ15.
  90. int_ok:
  91. ;-----
  92. ; Add Transceiver Bit and write interface register.
  93. ;-----
  94.     cmp    byte ptr thin_not_thick,00 ; Now set the interface
  95.     jz    set_dix               ; Jump if thick
  96.     mov    al,ND_INTF_BNC           ; Select BNC interface.
  97.     jmp    short addxcv           ;
  98. set_dix:
  99.     mov    al,ND_INTF_DIX           ; Select DIX interface.
  100. addxcv:    
  101.     add    al,ah               ; combine with interrupt
  102.     out    dx,al               ; and write to the card
  103.     endm
  104.  
  105. terminate_board    macro
  106.     endm
  107.  
  108.     public    int_no, io_addr,thin_not_thick
  109. int_no        db    2,0,0,0        ;must be four bytes long for get_number.
  110. io_addr        dw    0300h,0        ; I/O address for card (jumpers)
  111. thin_not_thick    dw    1,0        ; Non-zero means thin net
  112.  
  113.     public    driver_class, driver_type, driver_name, driver_function, parameter_list
  114. driver_class    db    BLUEBOOK, IEEE8023, 0        ;from the packet spec
  115. driver_type    dw    86        ;from the packet spec
  116. driver_name    db    'ETHIIE',0    ;name of the driver.
  117. driver_function    db    2
  118. parameter_list    label    byte
  119.     db    1    ;major rev of packet driver
  120.     db    9    ;minor rev of packet driver
  121.     db    14    ;length of parameter list
  122.     db    EADDR_LEN    ;length of MAC-layer address
  123.     dw    GIANT    ;MTU, including MAC headers
  124.     dw    MAX_MULTICAST * EADDR_LEN    ;buffer size of multicast addrs
  125.     dw    0    ;(# of back-to-back MTU rcvs) - 1
  126.     dw    0    ;(# of successive xmits) - 1
  127. int_num    dw    0    ;Interrupt # to hook for post-EOI
  128.             ;processing, 0 == none,
  129.  
  130. is_186        db    0
  131.  
  132. ;
  133. ;    Block input routine
  134. ;    CX = byte count, es:di = buffer location, ax = buffer address
  135.  
  136.     public    block_input
  137. block_input:
  138.     push    ax        ; save buffer address
  139.     loadport
  140.     setport EN_CCMD
  141.     pause_
  142.     mov    al,ENC_NODMA+ENC_PAGE0+ENC_START
  143.     out    dx,al
  144.     setport    EN0_RCNTLO    ; remote byte count 0
  145.     pause_
  146.     mov    al,cl
  147.     out    dx,al
  148.     setport    EN0_RCNTHI
  149.     pause_
  150.     mov    al,ch
  151.     out    dx,al
  152.     pop    ax        ; get our page back
  153.     setport    EN0_RSARLO
  154.     pause_
  155.     out    dx,al        ; set as hi address
  156.     setport    EN0_RSARHI
  157.     pause_
  158.     mov    al,ah
  159.     out    dx,al
  160.     setport EN_CCMD
  161.     pause_
  162.     mov    al,ENC_RREAD+ENC_START    ; read and start
  163.     out    dx,al
  164.     setport    ND_DATAPORT
  165.     pause_
  166.     cmp    is_186,0
  167.     jnz    read_186
  168. read_loop:
  169.     in    al,dx        ; get a byte
  170.     stosb            ; save it
  171.     loop    read_loop
  172.     ret
  173. read_186:
  174.     inc    cx        ; make even
  175.     shr    cx,1        ; word count
  176.     db    0f3h, 06dh    ;masm 4.0 doesn't grok "rep insw"
  177.     ret
  178. ;
  179. ;    Block output routine
  180. ;    CX = byte count, ds:si = buffer location, ax = buffer address
  181.  
  182. block_output:
  183.     assume    ds:nothing
  184.     push    ax        ; save buffer address
  185.     inc    cx        ; make even
  186.     and    cx,0fffeh
  187.     loadport
  188.     setport EN_CCMD
  189.     pause_
  190.     mov    al,ENC_NODMA+ENC_START
  191.     out    dx,al        ; stop & clear the chip
  192.     setport    EN0_RCNTLO    ; remote byte count 0
  193.     pause_
  194.     mov    al,cl
  195.     out    dx,al
  196.     setport    EN0_RCNTHI
  197.     pause_
  198.     mov    al,ch
  199.     out    dx,al
  200.     pop    ax        ; get our page back
  201.     setport    EN0_RSARLO
  202.     pause_
  203.     out    dx,al        ; set as lo address
  204.     setport    EN0_RSARHI
  205.     pause_
  206.     mov    al,ah
  207.     out    dx,al
  208.     setport EN_CCMD
  209.     pause_
  210.     mov    al,ENC_RWRITE+ENC_START    ; write and start
  211.     out    dx,al
  212.     setport    ND_DATAPORT
  213.     pause_
  214.     cmp    byte ptr is_186,0
  215.     jnz    write_186
  216. write_loop:
  217.     lodsb            ; get a byte
  218.     out    dx,al        ; save it
  219.     loop    write_loop
  220.     jmp    short block_output_1
  221. write_186:
  222.     shr    cx,1        ; word count
  223.     db    0f3h, 06fh    ;masm 4.0 doesn't grok "rep outsw"
  224. block_output_1:
  225.     mov    cx,0
  226.     setport    EN0_ISR
  227. tx_check_rdc:
  228.     in    al,dx
  229.     test    al,ENISR_RDC    ; dma done ???
  230.     jnz    tx_start
  231.     loop    tx_check_rdc
  232.     stc
  233.     ret
  234. tx_start:
  235.     clc
  236.     ret
  237.  
  238.     include    8390.asm
  239.     .LIST
  240.  
  241.     public    usage_msg
  242. usage_msg    db    "usage: ETHIIE [-n] [-d] [-w] <packet_int_no> <int_level> <io_addr> <thin_net>",CR,LF,'$'
  243.  
  244.     public    copyright_msg
  245. copyright_msg    db    "Packet driver for ICL EtherTeam16, version "
  246.         db    '0'+majver,".",'0'+version,".",'0'+dp8390_version,CR,LF,'$'
  247.  
  248. int_no_name    db    "Interrupt number ",'$'
  249. io_addr_name    db    "I/O port ",'$'
  250.  
  251. thin_msg    db    "Using the built-in transceiver (thinwire)",CR,LF,'$'
  252. thick_msg    db    "Using the external transceiver (thickwire)",CR,LF,'$'
  253.  
  254.     extrn    set_recv_isr: near
  255.  
  256. ;enter with si -> argument string, di -> word to store.
  257. ;if there is no number, don't change the number.
  258.     extrn    get_number: near
  259.  
  260. ;enter with dx -> name of word, di -> dword to print.
  261.     extrn    print_number: near
  262.  
  263.     public    parse_args
  264. parse_args:
  265. ;exit with nc if all went well, cy otherwise.
  266.     mov    di,offset int_no
  267.     call    get_number
  268.     mov    di,offset io_addr
  269.     call    get_number
  270.     mov    di,offset thin_not_thick    ; May override thick/thin cable flag
  271.     call    get_number
  272.     clc
  273.     ret
  274.  
  275.     extrn    etopen_diagn: byte
  276.  
  277. init_card:
  278. ;get the board data. This is (16) bytes starting at remote
  279. ;dma address 8000h. Put it in a buffer called board_data.
  280.     assume    ds:code
  281.  
  282.     or    endcfg,ENDCFG_WTS
  283.  
  284.     loadport
  285.     mov    al,endcfg
  286.     setport    EN0_DCFG
  287.     pause_
  288.     out    dx,al
  289.  
  290.     mov    cx,10h        ; get 16 bytes,
  291.     push    ds
  292.     pop    es        ; set es to ds
  293.     mov    di,offset board_data
  294.  
  295.     setport EN_CCMD
  296.     pause_
  297.     mov    al,ENC_NODMA+ENC_PAGE0+ENC_START
  298.     out    dx,al
  299.     setport    EN0_RCNTLO    ; remote byte count 0
  300.     pause_
  301.     mov    al,20h        ; count is actually doubled.
  302.     out    dx,al
  303.     setport    EN0_RCNTHI
  304.     pause_
  305.     xor    al,al        ; high byte of count is zero.
  306.     out    dx,al
  307.  
  308.     mov    ax,8000h    ; from address 0
  309.  
  310.     setport    EN0_RSARLO
  311.     pause_
  312.     out    dx,al        ; set as hi address
  313.     setport    EN0_RSARHI
  314.     pause_
  315.     mov    al,ah
  316.     out    dx,al
  317.     setport EN_CCMD
  318.     pause_
  319.     mov    al,ENC_RREAD+ENC_START    ; read and start
  320.     out    dx,al
  321.     loadport
  322.     setport    ND_DATAPORT
  323.     pause_
  324. sp_read_loop:
  325.     in    ax,dx        ; get a byte
  326.     stosb            ; save it
  327.     loop    sp_read_loop
  328.  
  329.     push    ds              ; Copy from card's address to current address
  330.     pop     es
  331.  
  332.     mov si, offset board_data    ; address is at start
  333.     mov di, offset curr_hw_addr
  334.     mov cx, EADDR_LEN       ; Copy one address length
  335.     rep     movsb           ; ..
  336.     ret
  337.  
  338.     public    print_parameters
  339. print_parameters:
  340. ;echo our command-line parameters
  341.     mov    di,offset int_no
  342.     mov    dx,offset int_no_name
  343.     call    print_number
  344.     mov    di,offset io_addr
  345.     mov    dx,offset io_addr_name
  346.     call    print_number
  347.     mov    dx,offset thin_msg
  348.     cmp    thin_not_thick,0    ; May override thick/thin cable flag
  349.     jne    print_parameters_1
  350.     mov    dx,offset thick_msg
  351. print_parameters_1:
  352.     mov    ah,9
  353.     int    21h
  354.     ret
  355.  
  356. code    ends
  357.  
  358.     end
  359.